---
title: Maven 环境配置
---
## Maven settings.xml 文件
Maven 使用阿里云云效私服。
```xml title=settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <mirror>
            <id>mirror</id>
            <mirrorOf>central,jcenter,!rdc-releases,!rdc-snapshots</mirrorOf>
            <name>mirror</name>
            <url>https://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>

    </mirrors>
<servers>
  <server>
    <id>rdc-releases</id>
    <username>62dd566101acbf842af9fcd0</username>
    <password>a5EPh5YzMS6H</password>
  </server>
  <server>
    <id>rdc-snapshots</id>
    <username>62dd566101acbf842af9fcd0</username>
    <password>a5EPh5YzMS6H</password>
  </server>
</servers>
    <profiles>
        <profile>
            <id>rdc</id>
         <properties>
      <altReleaseDeploymentRepository>
        rdc-releases::default::https://packages.aliyun.com/maven/repository/2256961-release-uvdbXC/
      </altReleaseDeploymentRepository>
      <altSnapshotDeploymentRepository>
        rdc-snapshots::default::https://packages.aliyun.com/maven/repository/2256961-snapshot-OgtSEM/
      </altSnapshotDeploymentRepository>
    </properties>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>rdc-releases</id>
                    <url>https://packages.aliyun.com/maven/repository/2256961-release-uvdbXC/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>rdc-snapshots</id>
                    <url>https://packages.aliyun.com/maven/repository/2256961-snapshot-OgtSEM/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>snapshots</id>
                    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>rdc-releases</id>
                    <url>https://packages.aliyun.com/maven/repository/2256961-release-uvdbXC/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>rdc-snapshots</id>
                    <url>https://packages.aliyun.com/maven/repository/2256961-snapshot-OgtSEM/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        <profile>
        <id>edas.oss.repo</id>
        <repositories>
            <repository>
                <id>edas-oss-central</id>
                <name>taobao mirror central</name>
                <url>http://wkq-img.oss-cn-chengdu.aliyuncs.com/repository</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
            </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>edas-oss-plugin-central</id>
                <url>http://wkq-img.oss-cn-chengdu.aliyuncs.com/repository</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </pluginRepository>
        </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>rdc</activeProfile>
        <activeProfile>edas.oss.repo</activeProfile>
    </activeProfiles>
</settings>


```

Maven 的 `settings.xml` 配置文件用于配置 Maven 构建工具的设置和行为。下面我们将解释这个配置文件的各个部分以及它们的作用。

### `<mirrors\>`（镜像）

```xml
<mirrors>
    <mirror>
        <id>mirror</id>
        <mirrorOf>central,jcenter,!rdc-releases,!rdc-snapshots</mirrorOf>
        <name>mirror</name>
        <url>https://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
</mirrors>
```

- **含义**：这部分用于定义 Maven 镜像，允许将 Maven 请求重定向到其他仓库。

- **作用**：在这里，我们配置了一个名为 "mirror" 的镜像，将中央仓库 (`central`) 和 JCenter 仓库 (`jcenter`) 的请求重定向到阿里云的 Maven 仓库。

### `<servers\>`（服务器）

```xml
<servers>
    <server>
        <id>rdc-releases</id>
        <username>5f9aba67a3bcee4a483449b5</username>
        <password>Z-nkj1RhTRBW</password>
    </server>
    <server>
        <id>rdc-snapshots</id>
        <username>5f9aba67a3bcee4a483449b5</username>
        <password>Z-nkj1RhTRBW</password>
    </server>
</servers>
```

- **含义**：这部分用于配置与仓库的身份验证相关的信息。

- **作用**：我们为两个仓库（`rdc-releases` 和 `rdc-snapshots`）配置了用户名和密码，以便进行仓库身份验证。

### `<profiles\>`（配置文件）

```xml
<profiles>
    <!-- 配置文件 1：rdc -->
    <profile>
        <id>rdc</id>
        <properties>
            <!-- 部署发行版到 rdc-releases 仓库 -->
            <altReleaseDeploymentRepository>rdc-releases::default::https://packages.aliyun.com/maven/repository/2045063-release-58c3rV/</altReleaseDeploymentRepository>
            <!-- 部署快照到 rdc-snapshots 仓库 -->
            <altSnapshotDeploymentRepository>rdc-snapshots::default::https://packages.aliyun.com/maven/repository/2045063-snapshot-VQBWY3/</altSnapshotDeploymentRepository>
        </properties>
        <repositories>
            <!-- 配置仓库 1：central -->
            <repository>
                <id>central</id>
                <url>https://maven.aliyun.com/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            <!-- 其他仓库配置略 -->
        </repositories>
        <!-- 插件仓库配置略 -->
    </profile>

    <!-- 配置文件 2：edas.oss.repo -->
    <profile>
        <id>edas.oss.repo</id>
        <!-- 仓库配置略 -->
    </profile>
</profiles>
```

- **含义**：这部分定义了 Maven 配置文件，允许自定义 Maven 的行为和仓库设置。

- **作用**：我们定义了两个配置文件，分别是 "rdc" 和 "edas.oss.repo"。配置文件包括了仓库、插件仓库和属性的设置。这允许您为不同的项目或环境定义不同的 Maven 设置。

### `<activeProfiles\>`（激活的配置文件）

```xml
<activeProfiles>
    <activeProfile>rdc</activeProfile>
    <activeProfile>edas.oss.repo</activeProfile>
</activeProfiles>
```

- **含义**：这部分指定了要激活的配置文件。

- **作用**：在这里，我们激活了两个配置文件，即 "rdc" 和 "edas.oss.repo"，这意味着这些配置文件中定义的设置将影响 Maven 构建和依赖解析的行为。

通过这个 `settings.xml` 配置文件，您可以自定义 Maven 的行为，包括镜像、仓库、身份验证和其他设置，以满足特定项目或环境的需求。希望这个教程能帮助您更好地理解 Maven 配置文件的作用。
## Maven 项目管理
当我们开发一个简单应用时，一般直接继承 `spring-boot-parent` 就可以了。

但是，如果项目复杂，一般会需要一个基础的 pom 文件,类似于 `spring-boot-dependencies`、`spring-cloud-dependencies`。
需要处理框架依赖的管理。在开发复杂项目时，也需要依赖版本进行的整合管理，所以我们需要新建一个 `pom.xml` 文件，主要处理的是
spring cloud 、 alibaba、spring-data 等技术体系依赖的管理。


```pom.xml title='项目统一依赖管理'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>pub.wkq</groupId>
    <artifactId>op-bom</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>17</java.version>
        <jdk.version>17</jdk.version>
        <spring.boot.version>3.0.2</spring.boot.version>
        <spring-cloud-version>2022.0.0</spring-cloud-version>
        <spring-cloud-alibaba-version>2022.0.0.0</spring-cloud-alibaba-version>
        <spring-boot-maven-verison>2.4.6</spring-boot-maven-verison>
        <querydsl-verion>5.0.0</querydsl-verion>
        <spring-data-bom-version>Neumann</spring-data-bom-version>
        <project.charset>UTF-8</project.charset>
        <commons-fileupload.version>1.3.1</commons-fileupload.version>
        <commons-upload-version>1.4</commons-upload-version>
        <commons-lang3.version>3.4</commons-lang3.version>
        <jjwt-version>0.9.0</jjwt-version>
        <fastjson-version>1.2.78</fastjson-version>
        <guava-version>31.0.1-jre</guava-version>
        <druid-starter-version>1.2.4</druid-starter-version>
        <swagger-version>2.9.2</swagger-version>
        <swagger-maven-plugin>3.1.7</swagger-maven-plugin>
        <swagger-code-gen-verison>2.3.1</swagger-code-gen-verison>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <jodd-version>5.1.4</jodd-version>
        <mapstruct-version>1.4.2.Final</mapstruct-version>
        <spring-statemachine.version>2.5.0</spring-statemachine.version>
    </properties>

    <developers>
        <developer>
            <email>2112954786@qq.com</email>
            <name>王开琦</name>
        </developer>
    </developers>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud-version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.statemachine</groupId>
                <artifactId>spring-statemachine-bom</artifactId>
                <version>${spring-statemachine.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba-version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
<!--            <dependency>-->
<!--                <groupId>com.only4play</groupId>-->
<!--                <artifactId>op-dependencies</artifactId>-->
<!--                <version>3.0.0</version>-->
<!--                <type>pom</type>-->
<!--                <scope>import</scope>-->
<!--            </dependency>-->
            <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-releasetrain -->
<!--            <dependency>-->
<!--                <groupId>org.springframework.data</groupId>-->
<!--                <artifactId>spring-data-releasetrain</artifactId>-->
<!--                <version>Neumann-SR9</version>-->
<!--                <type>pom</type>-->
<!--            </dependency>-->
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.11</version>
            </dependency>
            <dependency>
                <groupId>org.jodd</groupId>
                <artifactId>jodd-vtor</artifactId>
                <version>${jodd-version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
                <version>${druid-starter-version}</version>
            </dependency>
            <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
                <version>${commons-upload-version}</version>
            </dependency>
            <dependency>
                <groupId>io.jsonwebtoken</groupId>
                <artifactId>jjwt</artifactId>
                <version>${jjwt-version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>${fastjson-version}</version>
            </dependency>
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>${guava-version}</version>
            </dependency>
            <dependency>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct</artifactId>
                <version>${mapstruct-version}</version>
            </dependency>
            <dependency>
                <groupId>com.querydsl</groupId>
                <artifactId>querydsl-sql</artifactId>
                <version>${querydsl-verion}</version>
            </dependency>
            <dependency>
                <groupId>com.querydsl</groupId>
                <artifactId>querydsl-collections</artifactId>
                <version>${querydsl-verion}</version>
            </dependency>
            <dependency>
                <groupId>com.querydsl</groupId>
                <artifactId>querydsl-jpa</artifactId>
                <version>${querydsl-verion}</version>
            </dependency>
            <dependency>
                <groupId>com.querydsl</groupId>
                <artifactId>querydsl-sql-spring</artifactId>
                <version>${querydsl-verion}</version>
            </dependency>
            <dependency>
                <groupId>com.querydsl</groupId>
                <artifactId>querydsl-sql-codegen</artifactId>
                <version>${querydsl-verion}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.jodd</groupId>
                <artifactId>jodd-bean</artifactId>
                <version>${jodd-version}</version>
            </dependency>
            <dependency>
                <groupId>commons-validator</groupId>
                <artifactId>commons-validator</artifactId>
                <version>1.6</version>
            </dependency>
            <dependency>
                <groupId>io.vavr</groupId>
                <artifactId>vavr</artifactId>
                <version>1.0.0-alpha-3</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${swagger-version}</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${swagger-version}</version>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring.boot.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
        </plugins>
    </build>
</project>
```
在很多时候，使用统一的 Maven 是处理不了全部的依赖冲突的，所以一般在整个项目中会指定某些依赖的版本。不完全依赖父类进行依赖的管理。
## Maven 脚手架及插件
`maven-assembly-plugin` 打包插件，可以打包好运行脚本。

代码生成器插件可以生成关于这个领域对象所有相关的代码。
